package kr.kwakyc.puzzle;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class Game {
	
	private Ranking ranking;
	
	private ImagePanel imagePanel;
	private SolutionPanel solutionPanel;
	private TimerPanel timerPanel;
	
	public Game(String filePath, int tileSize, Level level, Ranking ranking) {
		this.ranking = ranking; 
		
		JFrame frame = new JFrame("그림 퍼즐 맞추기");
		frame.setLocation(400, 200);
		frame.setPreferredSize(new Dimension(650, 450));
		Container contentPane = frame.getContentPane();
		
		imagePanel = new ImagePanel(filePath, tileSize, level, this);
		contentPane.add(imagePanel, BorderLayout.WEST);
		
		JPanel helpPanel = new JPanel();
		solutionPanel = new SolutionPanel(imagePanel.getImage());
		timerPanel = new TimerPanel();
		helpPanel.add(solutionPanel);
		helpPanel.add(timerPanel);
		
		contentPane.add(helpPanel, BorderLayout.CENTER);
		
		frame.pack();
		frame.setVisible(true);
	}
	
	public void gameClear(){
		timerPanel.finish();
		int clearSecond = timerPanel.getSecond();
		ranking.showRankingInputFrame(clearSecond);
	}
	
}
